package org.minproject.my_library_back.controller;

import jakarta.annotation.Resource;
import org.minproject.my_library_back.common.CommonResponse;
import org.minproject.my_library_back.domain.Information;
import org.minproject.my_library_back.service.InformationService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class InformationController {
    @Resource
    private InformationService informationService;

    @GetMapping("/informations/")
    public CommonResponse<List<Information>> getInformations() throws Exception{
        return informationService.getInformations();
    }

    @GetMapping("/informations/{id}")
    public CommonResponse<List<Information>> getInformationById(@PathVariable("id") int id) throws Exception{
        return informationService.getInformationById(id);
    }

    @PostMapping("/informations/sort")
    public CommonResponse<List<Information>> getInformationBySort(@RequestBody Information information) throws Exception{
        return informationService.getInformationBySort(information);
    }

    @PostMapping("/informations/")
    public CommonResponse<Information> addInformation(@RequestBody Information information) throws Exception{
        return informationService.addInformation(information);
    }

    @PostMapping("/informations/{id}")
    public CommonResponse<Information> deleteInformation(@PathVariable("id") int id) throws Exception{
        return informationService.deleteInformation(id);
    }
}
